package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.UserAuthInfoMapper;
import com.cdks.wuxiu.entity.mysql.UserAuthInfo;

import java.util.List;

import org.springframework.stereotype.Service;


/**
 * 用户认证信息 服务实现类
 */
@Service
public class UserAuthInfoServiceImpl extends ServiceImpl<UserAuthInfoMapper, UserAuthInfo> implements UserAuthInfoService {

    @Override
    public String getPortrait(long userId) {
        QueryWrapper<UserAuthInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserAuthInfo::getUserId, userId)
                        .eq(UserAuthInfo::getType, Constant.AUDIT_TYPE_PORTRAIT)
                        .eq(UserAuthInfo::getStatus, Constant.AUDIT_STATUS_WAIT);

        UserAuthInfo info  = baseMapper.selectOne(wrapper);
        if (info == null)
        {
            return null;
        }

        return info.getInfo();
    }

    @Override
    public String getNickname(long userId) {
        QueryWrapper<UserAuthInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserAuthInfo::getUserId, userId)
                        .eq(UserAuthInfo::getType, Constant.AUDIT_TYPE_NICKNAME)
                        .eq(UserAuthInfo::getStatus, Constant.AUDIT_STATUS_WAIT);

        UserAuthInfo info  = baseMapper.selectOne(wrapper);
        if (info == null)
        {
            return null;
        }

        return info.getInfo();
    }

    @Override
    public Long getUserByIdCard(String idCard) {
        QueryWrapper<UserAuthInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserAuthInfo::getInfo, idCard)
                        .eq(UserAuthInfo::getType, Constant.AUDIT_TYPE_REALNAME)
                        .eq(UserAuthInfo::getStatus, Constant.AUDIT_STATUS_PASS);

        UserAuthInfo info  = baseMapper.selectOne(wrapper);
        if (info == null)
        {
            return null;
        }

        return info.getUserId();
    }

    @Override
    public int refuseData(int type, long userId) {
        return baseMapper.refuseData(type, userId);
    }

    @Override
    public UserAuthInfo getInfoByType(int type, long userId) {
        QueryWrapper<UserAuthInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserAuthInfo::getUserId, userId)
                        .eq(UserAuthInfo::getType, type)
                        .eq(UserAuthInfo::getStatus, Constant.AUDIT_STATUS_PASS);

        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<UserAuthInfo> getListByStatus(int status, long userId) {
        QueryWrapper<UserAuthInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserAuthInfo::getUserId, userId)
                        .eq(UserAuthInfo::getStatus, status);

        return baseMapper.selectList(wrapper);
    }    
}
